<!DOCTYPE html><!--suppress ALL-->
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">轮播描述</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" lay-reqtext="不能为空" value="美女展示" autofocus class="layui-input">
            <tip>描述当前此轮播图的信息。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">是否显示</label>
        <div class="layui-input-block">
            <input type="radio" name="isshow" value="1" title="显示" checked>
            <input type="radio" name="isshow" value="0" title="隐藏">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">轮播链接</label>
        <div class="layui-input-block">
            <input type="text" name="link" lay-verify="required" value="#" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">轮播图片</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" id="test8">选择文件</button>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-danger" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/axios/axios.js"></script>
<script>
    layui.use(['form', 'upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            $ = layui.$;

        var uploadInst = upload.render({
            elem: '#test8'
            , auto: false
        })


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let formdata = new FormData()
            formdata.append("title",data.field.title);
            formdata.append("link",data.field.link);
            formdata.append("isshow",data.field.isshow);
            var f = document.querySelector("input[name=file]");
            formdata.append("file",f.files[0])
            axios({
                url:'/cal/save',
                method:'post',
                data:formdata,
            }).then(res=>{
                let index = layer.alert(res.data.msg,{title:'成功保存'},function(){
                    layer.close(index);
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                })
            }).catch(err=>console.log(err))


            return false;
        });

    });
</script>
</body>
</html>
